class Person(object):
    def __init__(self,no,name):
        self.no=no
        self.name=name
class Student(Person):  # 学生
    def __init__(self,sno,sname):
        self.sno = sno
        self.sname = sname
        self.cour_list = []

    def search(self):  # 查看课程
        for c in self.cour_list:
            print(f"{self.sname}选了{c.cname}")

    def add_course(self, cour):  # 添加课程
        self.cour_list.append(cour)


class Course:  # 课程
    def __init__(self, cno, cname, teacher=None):
        self.cno = cno
        self.cname = cname
        self.teacher = teacher

    def search(self):
        print(f"{self.cno}, {self.cname}, {self.teacher.tname}")

    # 设置老师
    def set_teacher(self, teacher):
        self.teacher = teacher

#
class Teacher(Person):  # 老师
    def __init__(self, tno, tname, tphone):
        self.tno = tno
        self.tname = tname
        self.tphone = tphone
        self.student_list=[]
    def chakan(self):
        print(f"{self.tname}老师的学生有:")
        for c in self.student_list:
            print(c, end=",")
# #接下来创建6个课程, 6个老师. 给课程安排好老师. 然后创建30个学⽣.
# #每个学⽣随机被分配3个课程. 最终显⽰出这30个学⽣的选课情况以及任课老师的姓名、电话
#
import random
c1 = Course("01", "高等数学")
c2 = Course("02", "大学英语")
c3 = Course("03", "C语言")
c4 = Course("04", "Python")
c5 = Course("05", "马克思原理")
c6 = Course("06", "体育")

t1 = Teacher("01", "唐伯虎", "13301122001")
t2 = Teacher("02", "祝枝山", "13301122002")
t3 = Teacher("03", "文征明", "13301122003")
t4 = Teacher("04", "李白", "13301122004")
t5 = Teacher("05", "黄冠", "13301122005")
t6 = Teacher("06", "谢晋", "13301122006")

# 给课程设置老师
c1.set_teacher(t1)
c2.set_teacher(t2)
c3.set_teacher(t3)
c4.set_teacher(t4)
c5.set_teacher(t5)
c6.set_teacher(t6)

c_lst = [c1, c2, c3, c4, c5, c6]
t_lst=[t1,t2,t3,t4,t5,t6]
stu_lst = []
for i in range(30):  # 循环30次.
    stu = Student(i, "学生" + str(i))  # 创建30个学生
    # 生成随机的三个数字. 对应的是三个课程索引
    s = set()
    while len(s) < 3:
        s.add(random.randint(0, 5))
    # 把随机的三个课程索引对应的课程设置给学生
    for n in s:
        # print(n) # ???? 随机出来的课程的索引
        stu.add_course(c_lst[n])
        t_lst[n].student_list.append(stu.sname)
    stu_lst.append(stu)  # 加到列表
# 显示学生的选课情况以及老师的电话
for s in stu_lst:
    print(f"学生编号:{s.sno}, 学生姓名:{s.sname}")
    # 拿到学生的课程信息
    for c in s.cour_list:
        print(f"\t课程编号:{c.cno}, 课程名称: {c.cname}, 任课老师是：{c.teacher.tname},任课老师的电话是:{c.teacher.tphone}")
t1.chakan()